package com.jic.member.controller.rest;

import com.alibaba.fastjson.JSONArray;
import com.jic.common.base.vo.RestResult;
import com.jic.common.redis.RedisClientTemplate;
import com.jic.enums.RedisKey;
import com.jic.member.entity.Feedback;
import com.jic.member.entity.MememberUser;
import com.jic.member.request.AddFeedBackRequest;
import com.jic.member.service.FeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("apiFeedBack")
@Api(value = "APi-意见反馈",tags = "APi-意见反馈")
public class ApiFeedBackController {

    @Resource
    private RedisClientTemplate redisClientTemplate;
    @Resource
    private FeedbackService feedbackService;

    @ApiOperation("提交反馈")
    @ResponseBody
    @PostMapping("addFeedBack")
    public RestResult<String> addFeedBack(@RequestBody AddFeedBackRequest addFeedBackRequest){
        String token = addFeedBackRequest.getToken();
        RestResult result = new RestResult();
        String memStr = redisClientTemplate.get(RedisKey.H5_LOGIN_TOKEN_.getName() + token);
        MememberUser member = JSONArray.parseObject(memStr, MememberUser.class);
        if (member == null){
            return RestResult.error("4000","登录失效");
        }
        if (StringUtils.isEmpty(addFeedBackRequest.getContent())){
            return RestResult.error("9999","反馈内容不能为空");
        }
        result = feedbackService.insertFeedBack(member ,addFeedBackRequest);
        return result;
    }


}
